package com.deepclassifieds.daas.common;

public final class ShardNumber implements Comparable<ShardNumber> {
	
	public static final int MAX_SHARD_NUMBER = 99;
	
	private final int number;

	public ShardNumber(int number) {
		if(number < 0) {
			throw new IllegalArgumentException("shard number cannot be negative: " + number);
		}
		if(number > MAX_SHARD_NUMBER) {
			throw new IllegalArgumentException("shard number cannot be greater than " +
					MAX_SHARD_NUMBER + ": " + number);
		}
		this.number = number;
	}

	public int getNumber() {
		return number;
	}

	@Override
	public int hashCode() {
		return number;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		ShardNumber other = (ShardNumber) obj;
		return number == other.number;
	}

	@Override
	public int compareTo(ShardNumber other) {
		return this.number - other.number;
	}
	

}
